home *** CD-ROM | disk | FTP | other *** search
- unit ContextM;
-
- interface
-
- uses
- Windows, ComObj, ComServ, ShlObj, ActiveX, ShellApi, SysUtils,
- Classes, WizMain;
-
- Const
- CLSID_ContextMenuShellExtension: TGUID = (
- D1:$9F2214C0; D2:$2002; D3:$11D2; D4:($AF, $3E, $44, $45, $53, $54, $00, $00));
-
- type
- TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
- private
- szFile: array[0..MAX_PATH] of Char;
- szFiles: array of string;
- public
- function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
- uFlags: UINT): HResult; stdcall;
- function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
- function GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
- pszName: LPSTR; cchMax: UINT): HResult; stdcall;
- function Initialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
- hKeyProgID: HKEY): HResult; stdcall;
- end;
-
- implementation
-
- function TContextMenu.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
- idCmdLast, uFlags: UINT): HResult;
- begin
- // Add one menu item to context menu
- InsertMenu (Menu, indexMenu, MF_STRING or MF_BYPOSITION, idCmdFirst,
- 'Move Html Files...');
- // Return number of menu items added
- Result := 1;
- end;
-
- function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
- var
- i: integer;
- begin
- // Make sure we are not being called by an application
- if HiWord(Integer(lpici.lpVerb)) <> 0 then
- begin
- Result := E_FAIL;
- Exit;
- end;
- // Make sure we aren't being passed an invalid argument number
- if LoWord(lpici.lpVerb) > 0 then
- begin
- Result := E_INVALIDARG;
- Exit;
- end;
- // Execute the command specified by lpici.lpVerb.
- if LoWord(lpici.lpVerb) = 0 then
- begin
- // try to invoke window here
- with TWizardMain.Create(nil) do
- begin
- for i := 0 to Length(szFiles)-1 do
- ListBox1.Items.Add(szFiles[i]);
- ShowModal;
- Free;
- end;
- end;
- Result := NOERROR;
- end;
-
- function TContextMenu.GetCommandString(idCmd, uType: UINT; pwReserved: PUINT;
- pszName: LPSTR; cchMax: UINT): HRESULT;
- begin
- if idCmd = 0 then
- begin
- // return help string for menu item
- strCopy(pszName, 'Invoke HomeGrown''s Html file move wizard');
- Result := NOERROR;
- end
- else
- Result := E_INVALIDARG;
- end;
-
- function TContextMenu.Initialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
- hKeyProgID: HKEY): HResult;
- var
- medium: TStgMedium;
- fe: TFormatEtc;
- i: integer;
- begin
- with fe do
- begin
- cfFormat := CF_HDROP;
- ptd := Nil;
- dwAspect := DVASPECT_CONTENT;
- lindex := -1;
- tymed := TYMED_HGLOBAL;
- end;
- // Fail the call if lpdobj is Nil.
- if lpdobj = Nil then
- begin
- Result := E_FAIL;
- Exit;
- end;
- // Render the data referenced by the IDataObject pointer to an HGLOBAL
- // storage medium in CF_HDROP format.
- Result := lpdobj.GetData(fe, medium);
- if Failed(Result) then Exit;
- // copy all the files into szFiles
- for i := 0 to DragQueryFile(medium.hGlobal, $FFFFFFFF, Nil, 0)-1 do
- begin
- DragQueryFile(medium.hGlobal, i, szFile, SizeOf(szFile));
- SetLength(szFiles, Length(szFiles)+1);
- szFiles[Length(szFiles)-1] := string(szFile);
- end;
- Result := NOERROR;
- ReleaseStgMedium(medium);
- end;
-
- initialization
- TComObjectFactory.Create(ComServer, TContextMenu, CLSID_ContextMenuShellExtension,
- '', 'HomeGrown''s Html File Mover', ciMultiInstance);
-
- end.
-